SELECT COLNO,
       COLNAME,
       CASE
           WHEN TYPESCHEMA NOT LIKE 'SYS%' THEN
            TRIM(TYPESCHEMA) || '.'
       ELSE '' END|| TYPENAME || 
       CASE WHEN TYPENAME NOT IN('DB2SECURITYLABEL', 'GRAPHIC', 'DATE', 'TIME', 'TIMESTAMP', 'SMALLINT', 'INTEGER', 'BIGINT') AND length > 0 
           THEN '(' || LENGTH || CASE WHEN scale > 0 THEN ',' || scale ELSE '' END|| ')'  ELSE '' END COLTYPE,
       DEFAULT,
       decode(NULLS, 'Y', 'NOT NULL') NULLABLE,
       COLLATIONNAME COLLATION,
       LENGTH,AVGCOLLEN,COLCARD,NUMNULLS,
       CODEPAGE
FROM   SYSCAT.COLUMNS
WHERE  TABNAME = UPPER(:V1)
AND   (:V2 IS NULL OR TABSCHEMA = UPPER(:V2))
ORDER  BY TABSCHEMA,COLNO
WITH UR;
